package cn.edu.sgu.www.mhxysy.controller.xingyin;

import cn.edu.sgu.www.mhxysy.consts.CustomConstants;
import cn.edu.sgu.www.mhxysy.consts.CustomMessages;
import cn.edu.sgu.www.mhxysy.consts.MimeTypes;
import cn.edu.sgu.www.mhxysy.dto.xingyin.XingyinViewAttributeDTO;
import cn.edu.sgu.www.mhxysy.entity.xingyin.XingyinViewAttribute;
import cn.edu.sgu.www.mhxysy.pager.xingyin.XingyinViewAttributePager;
import cn.edu.sgu.www.mhxysy.restful.JsonPage;
import cn.edu.sgu.www.mhxysy.restful.JsonResult;
import cn.edu.sgu.www.mhxysy.service.xingyin.XingyinViewAttributeService;
import cn.edu.sgu.www.mhxysy.vo.xingyin.XingyinViewAttributeVO;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @author 沐雨橙风ιε
 * @version 1.0
 */
@Api(tags = "星印预览属性管理")
@ApiSupport(author = CustomConstants.AUTHOR)
@Validated
@RestController
@RequestMapping(path = "/xingyin_view_attribute", produces = MimeTypes.APPLICATION_JSON_CHARSET_UTF_8)
public class XingyinViewAttributeController {

    private final XingyinViewAttributeService xingyinViewAttributeService;

    @Autowired
    public XingyinViewAttributeController(XingyinViewAttributeService xingyinViewAttributeService) {
        this.xingyinViewAttributeService = xingyinViewAttributeService;
    }

    @ApiOperation("添加星印预览属性")
    @ApiOperationSupport(ignoreParameters = "id")
    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    public JsonResult<Void> insert(@Validated XingyinViewAttributeDTO xingyinViewAttributeDTO) {
        xingyinViewAttributeService.insert(xingyinViewAttributeDTO);

        return JsonResult.success(CustomMessages.INSERT_SUCCESS);
    }

    @ApiOperation("通过ID删除星印预览属性")
    @RequestMapping(value = "/deleteById", method = RequestMethod.POST)
    public JsonResult<Void> deleteById(
            @ApiParam(name = "id", value = "星印预览属性ID", required = true)
            @NotNull(message = CustomMessages.ID_NOT_NULL) Integer id) {
        xingyinViewAttributeService.deleteById(id);

        return JsonResult.success(CustomMessages.DELETE_SUCCESS);
    }

    @ApiOperation("通过ID修改星印预览属性")
    @RequestMapping(value = "/updateById", method = RequestMethod.POST)
    public JsonResult<Void> updateById(@Validated XingyinViewAttributeDTO xingyinViewAttributeDTO) {
        xingyinViewAttributeService.updateById(xingyinViewAttributeDTO);

        return JsonResult.success(CustomMessages.UPDATE_SUCCESS);
    }

    @ApiOperation("查询星印的预览属性列表")
    @RequestMapping(value = "/selectByXingyinId", method = RequestMethod.GET)
    public JsonResult<List<XingyinViewAttributeVO>> selectByXingyinId(
            @ApiParam(name = "xingyinId", value = "星印类型ID", required = false)
            @RequestParam(required = false) Integer xingyinId) {
        List<XingyinViewAttributeVO> list = xingyinViewAttributeService.selectByXingyinId(xingyinId);

        return JsonResult.success(null, list);
    }

    @ApiOperation("分页查询星印预览属性列表")
    @RequestMapping(value = "/selectByPage", method = RequestMethod.GET)
    public JsonResult<JsonPage<XingyinViewAttribute>> selectByPage(XingyinViewAttributePager pager) {
        Page<XingyinViewAttribute> page = xingyinViewAttributeService.selectByPage(pager);

        return JsonResult.restPage(page);
    }

}